//
//  KDataDrivenConfigure.h
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 ZHBen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "KDDConfig.h"
#import "KDDSectionData.h"
#import "KDDPosition.h"
#import <objc/runtime.h>
@protocol KDataDrivenConfigure <NSObject>

- (void)addModelConfig:(KDDConfig *)config;

- (KDDConfig *)modelConfigWithID:(NSString *)configID;

- (void)addRegisterInfo:(KDDRegisterInfo *)info;

- (void)registerDecorationView:(Class)cls insets:(UIEdgeInsets)insets zIndex:(NSInteger)zIndex reuseID:(NSString *)reuseID;

- (KDDRegisterInfo *)registerInfoForReuseID:(NSString *)reuseID viewType:(KDDViewType)viewType;

@end

@protocol KDataDrivenOperation <NSObject>

// Batch Update
- (void)performBatchUpdates:(void (^)(void))updates animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
// Section Update
- (void)insertSections:(NSArray<KDDSectionData *> *)sectionDataList atIndexes:(NSIndexSet *)indexSet;

- (void)deleteSectionsAtIndexes:(NSIndexSet *)indexSet;

- (void)modifySections:(NSArray<KDDSectionData *> *)sectionDataList atIndexes:(NSIndexSet *)indexSet;

- (void)reloadSectionsAtIndexes:(NSIndexSet *)indexSet;
// Item Update
- (void)insertModels:(NSArray *)modelList atPositions:(NSArray<KDDPosition *> *)positionList;

- (void)deleteModelsAtPositions:(NSArray<KDDPosition *> *)positionList;

- (void)modifyModelsAtPositions:(NSArray<KDDPosition *> *)positionList withModels:(NSArray *)modelList;

- (void)reloadModelsAtPositions:(NSArray<KDDPosition *> *)positionList;
// List Update
- (void)modifyData:(NSArray<KDDSectionData *> *)sectionDataList;

- (void)reloadData;

@end

@protocol KDataDrivenStorage <KDataDrivenOperation>

@property (strong,readonly,nonatomic) NSArray<KDDSectionData *> * data;

- (KDDPosition *)positionOfModel:(NSObject *)model inSection:(NSInteger)sectionIndex;

- (NSArray<KDDPosition *> *)positionsOfModels:(NSArray *)modelList notFound:(NSMutableArray **)notFound;

- (NSArray<KDDPosition *> *)positionsOfModels:(NSArray *)modelList section:(NSInteger)section notFound:(NSMutableArray **)notFound;

- (NSObject *)modelAtPosition:(KDDPosition *)position;

- (NSArray *)modelsAtPositions:(NSArray<KDDPosition *> *)positionList notFound:(NSMutableArray<KDDPosition *> **)notFound;

// Other
- (void)switchModelAtPositions:(NSArray<KDDPosition *> *)positionList1 toPositions:(NSArray<KDDPosition *> *)positionList2;

- (NSArray<KDDPosition *> *)positionListOfSection:(KDDSectionData *)sectionData sectionIndex:(NSInteger)sectionIndex rowOffset:(NSInteger)rowOffset modelList:(NSMutableArray **)modelList;

- (void)splitSection:(NSInteger)sectionIndex rowOffset:(NSInteger)rowOffset;

- (void)connectSectionsInRange:(NSRange)range;

- (void)insertSectionData:(KDDSectionData *)sectionData inSection:(NSInteger)sectionIndex rowOffset:(NSInteger)rowOffset;

@end

@protocol KDataDriven <NSObject>

//可用作UIScrollViewDelegate
@property (weak,nonatomic) id additionalDelegate;

@property (nonatomic) BOOL enableIndexTitles;

- (void)applyToLayoutView:(__kindof UIView *)layoutView;

- (__kindof UIView *)layoutView;

- (id<KDataDrivenConfigure>)configure;

- (id<KDataDrivenStorage>)storage;

- (__kindof UIView *)wrapperViewAtPosition:(KDDPosition *)position;

- (NSArray<KDDPosition *> *)visiblePositionList;

- (void)selectItemAtPosition:(KDDPosition *)position animated:(BOOL)animated scrollPosition:(KDDScrollPosition)scrollPosition;

- (void)selectItemAtPosition:(KDDPosition *)position animated:(BOOL)animated scrollPosition:(KDDScrollPosition)scrollPosition offsetY:(CGFloat)offsetY;

- (CGRect)rectForItemAtPosition:(KDDPosition *)position;

- (NSInteger)numberOfSections;

@end
